/******************************************************************************
	This file is a part of the Snapshot Bioinformatics Project

	Copyright (C) 2012-2013 Jarom Schow

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "CreateSeqDatabaseDlg.h"

#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QComboBox>

#include "Workbench.h"
#include "SqlServer.h"

/**
**/
CreateSeqDatabaseDlg::CreateSeqDatabaseDlg( QWidget *parent, Bio::SqlServer *server ) : QDialog( parent ),
	m_server( server )
{
	initLayout();
}

/**
**/
CreateSeqDatabaseDlg::~CreateSeqDatabaseDlg()
{
}

/**
**/
void CreateSeqDatabaseDlg::accept()
{	
	m_server->createSeqDatabase( m_nameEdit->text(), m_authEdit->text(), m_descEdit->text() );

	QDialog::accept();
}

/**
**/
void CreateSeqDatabaseDlg::initLayout()
{
	int			row = 0;
	int			col = 0;
	QLabel		*lbl;
	QPushButton	*btn;
	QGridLayout	*layout = new QGridLayout;

	setLayout( layout );

	lbl = new QLabel( tr( "Name:" ), this );
	layout->addWidget( lbl, row, col++ );

	m_nameEdit = new QLineEdit( this );
	layout->addWidget( m_nameEdit, row, col++ );

	row++;
	col= 0;

	lbl = new QLabel( tr( "Authority:" ), this );
	layout->addWidget( lbl, row, col++ );

	m_authEdit = new QLineEdit( this );
	layout->addWidget( m_authEdit, row, col++, 1, 3 );

	row++;
	col = 0;

	lbl = new QLabel( tr( "Description:" ), this );
	layout->addWidget( lbl, row, col++ );

	m_descEdit = new QLineEdit( this );
	layout->addWidget( m_descEdit, row, col++, 1, 3 );

	row++;
	col = 0;

	layout->setColumnStretch( 1, 100 );
	layout->setRowStretch( row, 100 );

	row++;

	QHBoxLayout	*btnLayout = new QHBoxLayout;

	layout->addLayout( btnLayout, row, 0, 1, 4 );

	btnLayout->setMargin( 0 );
	btnLayout->addStretch( 100 );

	btn = new QPushButton( tr( "Accept" ), this );
	connect( btn, SIGNAL(clicked()), this, SLOT(accept()) );
	btnLayout->addWidget( btn );

	btn = new QPushButton( tr( "Cancel" ), this );
	connect( btn, SIGNAL(clicked()), this, SLOT(reject()) );
	btnLayout->addWidget( btn );
}
